<template xmlns:el-col="http://www.w3.org/1999/html">
  <div class="app-container">

    <el-row>
      <el-card style="height: 647px">
        <template #header>
          <span class="card-header-title">库存物料</span>
<!--          <span v-if="showModals" class="modals">！！！！请结付尾款,否则系统将于12月31日锁定！！！！</span>-->
        </template>
        <el-form :model="stockQueryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
<!--          <el-form-item label="产线编号" prop="GropSc">
            <el-input
              v-model="stockQueryParams.GropSc"
              placeholder="请输入产线编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>-->
          <el-form-item label="产品型号" prop="BARCODE">
            <el-input
              v-model="stockQueryParams.BARCODE"
              placeholder="请输入产品型号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="库位号" prop="locationId">
            <el-input
              v-model="stockQueryParams.locationId"
              placeholder="请输入库位号"
              clearable
              @keyup.enter.native="handleStockQuery"
            />
          </el-form-item>

          <!--          <el-form-item label="" prop="STS">
                      <el-select
                        v-model="stockQueryParams.STS"
                        placeholder="请选择库存状态"
                        clearable
                      >
                        <el-option
                          v-for="dict in dict.type.kc_sts"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>-->

          <el-form-item label="状态" prop="STS">
            <el-select
              v-model="stockQueryParams.STS"
              placeholder="请选择库存状态"
              clearable
            >
              <el-option
                v-for="dict in dict.type.kc_sts"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="物料编号" prop="goodsId">
            <el-input
              v-model="stockQueryParams.goodsId"
              placeholder="请输入物料编号"
              clearable
              @keyup.enter.native="handleStockQuery"
            />
          </el-form-item>
          <el-form-item label="物料名称" prop="goodsName">
            <el-input
              v-model="stockQueryParams.goodsName"
              placeholder="请输入物料名称"
              clearable
              @keyup.enter.native="handleStockQuery"
            />
          </el-form-item>
          <el-form-item label="PO" prop="PO">
            <el-input
              v-model="stockQueryParams.PO"
              placeholder="请输入PO"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="SO" prop="SO">
            <el-input
              v-model="stockQueryParams.SO"
              placeholder="请输入SO"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="MID" prop="ITEM">
            <el-input
              v-model="stockQueryParams.ITEM"
              placeholder="请输入MID"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleStockQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
          <div class="float-right-container">
            <div class="chart-container">
              <div class="bar-container">
                <div class="bar" style="background-color: #c6f1aa; height: 20px;"></div>
                <div class="label">正常</div>
              </div>
              <div class="bar-container">
                <div class="bar" style="background-color: #ead6a3; height: 20px;"></div>
                <div class="label">占用</div>
              </div>
              <div class="bar-container">
                <div class="bar" style="background-color: #ec949b; height: 20px;"></div>
                <div class="label">锁定</div>
              </div>
            </div>
          </div>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              size="mini"
              :disabled = "stockMultiple"
              @click="createTask"
              v-hasPermi="['system:ORDERDETAIL:create']"
            >创建任务
            </el-button>
          </el-col>

          <right-toolbar :showSearch.sync="showSearch" @queryTable="getStockList"></right-toolbar>
        </el-row>
        <el-table height="400px"  v-loading="loading" border :data="STOCKList"  @selection-change="SelectionStock" :row-style="rowStyle">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column type="index" label="行号" width="55" align="center"/>
<!--          <el-table-column label="产线编号" align="center" prop="gropSc"/>-->
          <el-table-column label="产品型号" align="center" prop="barcode"/>
          <el-table-column label="入库单号" align="center" sortable prop="putinId"/>
          <el-table-column label="托盘号" align="center" sortable prop="ctl"/>
          <el-table-column label="库位" align="center" sortable prop="locationId"/>
          <el-table-column label="物料编号" align="center" sortable prop="goodsId"/>
          <el-table-column label="备注" align="center" prop="goodsName"/>
          <el-table-column label="数量" align="center" sortable prop="shelvesNum"/>
          <el-table-column label="储位" align="center" prop="stnr"/>
          <el-table-column label="订单编号" align="center" prop="trno"/>
          <el-table-column label="花序" align="center" prop="article"/>
          <el-table-column label="数量" align="center" prop="qty"/>
          <el-table-column label="PO" align="center" prop="po"/>
          <el-table-column label="SO" align="center" prop="so"/>
          <el-table-column label="MID" align="center" prop="item"/>
          <el-table-column label="订单编号" align="center" prop="ordno"/>
          <el-table-column label="尺寸" align="center" prop="cussize"/>
          <el-table-column label="材料编号" align="center" prop="itnbr"/>
          <el-table-column label="材料名称" align="center" prop="itdsc"/>
          <el-table-column label="状态" align="center" prop="sts">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.kc_sts" :value="scope.row.sts"/>
            </template>
          </el-table-column>
          <el-table-column label="下线时间" align="center" prop="productionDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="入库日期" align="center" prop="wareDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.wareDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="stockUpdate(scope.row, '锁定')"
              >锁定
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="stockUpdate(scope.row,'解锁')"
              >解锁
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--        <pagination
                  v-show="Stocktotal>0"
                  :total="Stocktotal"
                  :page.sync="stockQueryParams.pageNum"
                  :limit.sync="stockQueryParams.pageSize"
                  @pagination="getStockList"
                />-->
      </el-card>


      <el-card style="height: 400px;margin-top: 10px">
        <template #header>
          <span class="card-header-title">出库任务</span>
        </template>
        <el-row :gutter="10" class="mb8">
          <!--          <el-col :span="1.5">
                      <el-button
                        type="success"
                        size="mini"
                        :disabled="single"
                        @click="handleUpdate"
                        v-hasPermi="['system:ORDERDETAIL:edit']"
                      >修改状态
                      </el-button>
                    </el-col>-->
          <div class="float-right-container">
            <div class="chart-container">
              <div class="bar-container">
                <div class="bar" style="background-color: #faa5ac; height: 20px;"></div>
                <div class="label">未执行</div>
              </div>
              <div class="bar-container">
                <div class="bar" style="background-color: #ead6a3; height: 20px;"></div>
                <div class="label">堆垛机已写入</div>
              </div>
              <div class="bar-container">
                <div class="bar" style="background-color: #a9bfed; height: 20px;"></div>
                <div class="label">输送机已写入</div>
              </div>
              <div class="bar-container">
                <div class="bar" style="background-color: #a7dc83; height: 20px;"></div>
                <div class="label">堆垛机出库完成</div>
              </div>
            </div>
          </div>
        </el-row>
        <el-table border height="200px" ref="filterTable" v-loading="loading" :data="PICKINGWAVEGOODSList"
                  @selection-change="handleSelectionChange" :row-style="pkStyle">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column
            fixed
            type="index"
            label="行号"
            width="60"
            align="center"
          />
<!--          <el-table-column label="产线编号" align="center" prop="gropSc"/>-->
          <el-table-column label="产品型号" align="center" prop="barcode"/>
          <el-table-column label="库位编号" align="center" prop="locId"/>
          <el-table-column label="托盘编号" align="center" prop="ctl"/>
          <el-table-column label="物料编号" align="center" prop="goodId"/>
          <el-table-column label="出库数量" align="center" prop="goodsNum"/>
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ck_sts" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <el-table-column label="出库时间" align="center" prop="wareDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.wareDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="出库任务类型" align="center" prop="typests">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.typests" :value="scope.row.typests"/>
            </template>
          </el-table-column>
          <el-table-column label="目的库位" align="center" prop="eoutStand"/>
          <!--     -->
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
        <!-- 添加或修改出库物料明细对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="" prop="orderId">
              <el-input v-model="form.orderId" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="BUSINESSID">
              <el-input v-model="form.BUSINESSID" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="goodId">
              <el-input v-model="form.goodId" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="sts">
              <el-input v-model="form.sts" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="SPECIFICATION">
              <el-input v-model="form.SPECIFICATION" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="REMARK">
              <el-input v-model="form.REMARK" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
            <el-form-item label="" prop="scaleUnit">
              <el-input v-model="form.scaleUnit" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="goodsTypeId">
              <el-input v-model="form.goodsTypeId" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="addtime">
              <el-date-picker clearable
                              v-model="form.addtime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="" prop="endtime">
              <el-date-picker clearable
                              v-model="form.endtime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="" prop="UNIT">
              <el-input v-model="form.UNIT" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="storageAreaId">
              <el-input v-model="form.storageAreaId" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="locationId">
              <el-input v-model="form.locationId" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="" prop="storageId">
              <el-input v-model="form.storageId" placeholder="请输入"/>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-card>
    </el-row>


    <!--    &lt;!&ndash;明细&ndash;&gt;
        <el-row :gutter="15" style="margin-top: 20px">
          <el-card>
            <template #header>
              <span class="card-header-title">出库明细</span>
            </template>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button
                  type="success"
                  size="mini"
                  :disabled="single"
                  @click="handleUpdate"
                  v-hasPermi="['system:ORDERDETAIL:edit']"
                >修改状态
                </el-button>

              </el-col>
              <div class="float-right-container">
                <div class="chart-container">
                  <div class="bar-container">
                    <div class="bar" style="background-color: #faa5ac; height: 20px;"></div>
                    <div class="label">未执行</div>
                  </div>
                  <div class="bar-container">
                    <div class="bar" style="background-color: #a7dc83; height: 20px;"></div>
                    <div class="label">已执行</div>
                  </div>
                </div>
              </div>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

            </el-row>
            <el-table height="400px" v-loading="loading" row-class-name="tableRowClassName" border :data="ORDERDETAILList"
                      :row-class-name="tableRowClassName" @selection-change="handleSelectionChange" :row-style="rowStyle1" >
              <el-table-column type="selection" width="55" align="center"/>
              <el-table-column label="出库单号" align="center" prop="orderId"/>
              <el-table-column label="物料编号" align="center" prop="goodId"/>
              <el-table-column label="物料名称" align="center" prop="goodName"/>
              <el-table-column label="库位号" align="center" prop="locationId"/>
              <el-table-column label="托盘号" align="center" prop="ctl"/>
              <el-table-column label="状态" align="center" prop="sts">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.ck_mx_sts" :value="scope.row.sts"/>
                </template>
              </el-table-column>
    &lt;!&ndash;          <el-table-column label="出库类型"  align="center" sortable prop="type">&ndash;&gt;
    &lt;!&ndash;            <template slot-scope="scope">&ndash;&gt;
    &lt;!&ndash;              <dict-tag :options="dict.type.ck_type" :value="scope.row.type"/>&ndash;&gt;
    &lt;!&ndash;            </template>&ndash;&gt;
    &lt;!&ndash;          </el-table-column>&ndash;&gt;
              <el-table-column label="数量" align="center" prop="goodsNum"/>
              <el-table-column label="创建时间" align="center" prop="addtime" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.addtime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
            &lt;!&ndash; 添加或修改出库物料明细对话框 &ndash;&gt;
            <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
              <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="" prop="orderId">
                  <el-input v-model="form.orderId" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="BUSINESSID">
                  <el-input v-model="form.BUSINESSID" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="goodId">
                  <el-input v-model="form.goodId" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="sts">
                  <el-input v-model="form.sts" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="SPECIFICATION">
                  <el-input v-model="form.SPECIFICATION" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="REMARK">
                  <el-input v-model="form.REMARK" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
                <el-form-item label="" prop="scaleUnit">
                  <el-input v-model="form.scaleUnit" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="goodsTypeId">
                  <el-input v-model="form.goodsTypeId" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="addtime">
                  <el-date-picker clearable
                                  v-model="form.addtime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="" prop="endtime">
                  <el-date-picker clearable
                                  v-model="form.endtime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="" prop="UNIT">
                  <el-input v-model="form.UNIT" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="storageAreaId">
                  <el-input v-model="form.storageAreaId" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="locationId">
                  <el-input v-model="form.locationId" placeholder="请输入"/>
                </el-form-item>
                <el-form-item label="" prop="storageId">
                  <el-input v-model="form.storageId" placeholder="请输入"/>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
              </div>
            </el-dialog>
          </el-card>
        </el-row>-->

    <el-dialog
      title="修改出库订单状态"
      :visible.sync="dialogVisible"
      width="30%">
      <el-form :model="form">
        <el-form-item label="状态">
          <el-select v-model="form.sts" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.ck_mx_sts"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style>
.float-right-container {
  float: right; /* 容器向右浮动 */
  clear: both; /* 清除浮动，避免影响后续元素 */
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.chart-container {
  display: flex;
  align-items: center; /* 使所有条形图和标签垂直居中 */
  gap: 10px; /* 条形图之间的间隔 */
}

.bar-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* 使条形图和标签水平居中 */
}

.bar {
  width: 100px; /* 假设条形图的宽度为50px */
  margin-bottom: 5px; /* 条形图和标签之间的间隔 */
}

.label {
  font-size: 14px; /* 标签的字体大小 */
  color: #333; /* 标签的文字颜色 */
}

.modals{
  color: red; /* 红色字体 */
}

</style>

<script>
import {
  listORDERDETAIL,
  getORDERDETAIL,
  delORDERDETAIL,
  addORDERDETAIL,
  updateORDERDETAIL,
  creates, updateCkSts
} from "@/api/system/ORDERDETAIL";
import {delSTOCK, getSTOCK, listsSTOCK, listSTOCK, updateSTOCK} from "@/api/system/stock";
import {updateSts} from "@/api/system/ONGOODSSHELF";
import {listPICKINGWAVEGOODS} from "@/api/system/pickingwavegoods";

export default {
  dicts: ['ck_sts', 'kc_sts', 'ck_type', 'ck_mx_sts', 'typests'],
  name: "ORDERDETAIL",
  data() {
    return {
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      Stocktotal: 0,
      // 出库任务
      PICKINGWAVEGOODSList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      stockQueryParams: {
        pageNum: 1,
        pageSize: 10,
        putinId: null,
        putinIdLine: null,
        locationId: null,
        CTL: null,
        goodsId: null,
        GropSc: null,
        BARCODE: null,
        shelvesNum: null,
        wgh: null,
        STS: null,
        productionDate: null,
        wareDate: null,
        REMARK: null,
        stockId: null,
        storageId: null,
        VERSION: null,
        storageMode: null,
        providerId: null,
        DOCCTNUMBER: null,
        goodsTypeid: null,
        GOODSVOLUME: null,
        occupyNum: null,
        areaId: null,
        noticeId: null,
        oriBill: null,
        customerId: null,
        goodsSku: null,
        locIdName: null,
        goodsName: null,
        boxType: null,
        packingNum: null,
        ProDucLotId: null,
        Whseloc: null,
        HIGH: null,
        PRICE: null,
        PROBLEM: null,
        orderNum: null,
        CUSTOMER: null,
        REMARK2: null,
        ONSHELFUSERID: null,
        PARTDESC: null,
        HASVOLUME: null,
        warehousingId: null,
        upgoodsId: null,
        BarCodeTpe: null,
        BarCodef: null,
        lx: null,
        netWeigh: null,
        stsErp: null,
        stsDj: null,
        SPECIFICATION: null,
        gltrp: null,
        goodsMeasureId: null,
        SAPMSG: null,
        VKBUR: null,
        KUNAG: null,
        ZVKBUR: null,
        ZKUNAG: null,
        ZSOURCE: null,
        QTBY1: null,
        QTBY2: null,
        QTBY3: null,
        QTBY4: null,
        QTBY5: null,
        QTBY6: null,
        searchValue: null,
        STNR: null,
        TRNO: null,
        ARTICLE: null,
        QTY: null,
        PO: null,
        SO: null,
        ITEM: null,
        ORDNO: null,
        CUSSIZE: null,
        ITNBR: null,
        ITDSC: null
      },

      // 查询参数
      queryParams: {
        wareDates: [],
        pageNum: 1,
        pageSize: 10,
        PICKINGID: null,
        putinId: null,
        putinIdLine: null,
        DOCCTNUMBER: null,
        plcId: null,
        goodId: null,
        locId: null,
        CTL: null,
        OUTSTAND: null,
        STATUS: null,
        goodsNum: null,
        SPECIFICATION: null,
        productionDate: null,
        wareDate: null,
        providerId: null,
        UNIT: null,
        REMARK: null,
        outId: null,
        scaleUnit: null,
        mistockNum: null,
        pickingNum: null,
        PRICE: null,
        storageAreaId: null,
        storageId: null,
        goodsNumSj: null,
        ToWhseloc: null,
        typests: null,
        packingNum: null,
        ProDucLotId: null,
        BARCODE: null,
        goodsName: null,
        PROT: null,
        goodsMeasureId: null,
        DataType: null,
        VERSION: null,
        goodsTypeid: null,
        endtype: null,
        PARTDESC: null,
        upgoodsId: null,
        BarCodeTpe: null,
        BarCodef: null,
        GropSc: null,
        lx: null,
        netWeigh: null,
        stsErp: null,
        stsDj: null,
        gltrp: null,
        ONSHELFUSERID: null,
        wgh: null,
        HASVOLUME: null,
        warehousingId: null,
        EoutStand: null,
        SAPMSG: null
      },
      // 表单参数
      form: {},
      stockform: {},
      // 表单校验
      rules: {
        orderId: [
          {required: true, message: "$comment不能为空", trigger: "blur"}
        ],
      },
      // 选中数组
      STOCKList: [],
      goodsId: [],
      locationId: [],
      ctl: [],
      putinId: [],
      stocksIngle: true,
      stockMultiple: true,
      stockOpen: false,
      stock: {}
    };
  },
  getSummaries(param) {
    const {columns, data} = param;
    const sums = [];
    const sumFields = ['shelvesNum',]; // 手动指定需要合计的字段名

    columns.forEach((column, index) => {
      if (index === 0) {
        sums[index] = '合计';
      } else if (sumFields.includes(column.property)) {
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ''; // 可以根据需要添加单位
        } else {
          sums[index] = ' ';
        }
      } else {
        sums[index] = ''; // 不需要合计的字段显示为空
      }
    });
    return sums;
  },


  created() {
    this.getStockList();
    this.getList();
  },

  mounted() {

    // 设置定时器，每隔30秒调用一次
    this.fetchDataInterval = setInterval(() => {
      this.getStockList();
      this.getList();
    }, 30000); // 30000毫秒 = 30秒
  },
  beforeDestroy() {
    // 清除定时器
    if (this.fetchDataInterval) {
      clearInterval(this.fetchDataInterval);
    }
  },

  methods: {
    rowStyle({row, rowIndex}) {
      if (row.sts === "0") {
        return {backgroundColor: '#c6f1aa'}; // 返回被点击行的样式
      } else if (row.sts === '1') {
        return {backgroundColor: '#ead6a3'};
      } else if (row.sts === '2') {
        return {backgroundColor: '#ec949b'};
      }
      return {}; // 返回其他行的默认样式
    },
    pkStyle({row, rowIndex}) {
      if (row.status === "0") {
        return {backgroundColor: '#ec949b'}; // 返回被点击行的样式
      } else if (row.status === '1') {
        return {backgroundColor: '#ead6a3'};
      } else if (row.status === '2') {
        return {backgroundColor: '#a9bfed'};
      } else if (row.status === '10') {
        return {backgroundColor: '#a7dc83'};
      }
      return '';
    },
    /** 查询出库物料明细
     列表 */
    getList() {
      this.loading = true;
      listPICKINGWAVEGOODS(this.queryParams).then(response => {
        this.PICKINGWAVEGOODSList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getStockList() {
      this.loading = true;
      listsSTOCK(this.stockQueryParams).then(response => {
        this.STOCKList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        BUSINESSID: null,
        goodId: null,
        goodName: null,
        sts: null,
        SPECIFICATION: null,
        goodsNum: null,
        SORTID: null,
        REMARK: null,
        pageNum: null,
        WEITH: null,
        PRICE: null,
        scaleUnit: null,
        goodsTypeId: null,
        packingNum: null,
        addtime: null,
        endtime: null,
        totalVolume: null,
        GVOLUME: null,
        UNIT: null,
        storageAreaId: null,
        locationId: null,
        pickNum: null,
        trNum: null,
        xqType: null,
        buyNum: null,
        storageId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    handleStockQuery() {
      this.queryParams.pageNum = 1;
      this.getStockList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.handleStockQuery()
    },
    updateMessage() {
      this.getList();
      this.getStockList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.locationId = selection.map(item => item.locationId)
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    //库存选择
    SelectionStock(selection) {
      this.stocksIngle = selection.length !== 1
      console.log(selection, "124")
      this.goodsId = selection.map(item => item.goodsId)
      console.log(this.goodsId)
      this.locationId = selection.map(item => item.locationId)
      this.ctl = selection.map(item => item.ctl)
      this.putinId = selection.map(item => item.putinId)
      this.barcode = selection.map(item => item.barcode)
      this.stock = selection;
      this.stockMultiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加出库物料明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.dialogVisible = true
    },
    //库存修改状态
    stockUpdate(row, action) {
      const goodsId = row.goodsId;
      const locationId = row.locationId;
      const ctl = row.ctl;
      let sts;
      if (action === '解锁') {
        sts = "0";
      } else {
        sts = "2";
      }
      getSTOCK({goodsId: goodsId, locationId: locationId, ctl: ctl, sts: sts}).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.getStockList();
      });
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateORDERDETAIL(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addORDERDETAIL(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //库存修改状态
    submitFormStock() {
      this.$refs["stockform"].validate(valid => {
        if (valid) {
          console.log(this.stockform.sts)
          updateSTOCK(this.stockform).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.stockOpen = false;
            this.getStockList();
          });

        }
      });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除出库物料明细编号为"' + orderIds + '"的数据项？').then(function () {
        return delORDERDETAIL(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/ORDERDETAIL/export', {
        ...this.queryParams
      }, `ORDERDETAIL_${new Date().getTime()}.xlsx`)
    },

    //相邻库位添加
    create() {
      debugger
      // 遍历选中的对象
      this.stock.forEach(selectedItem => {
        // 检查库位尾数是否为2
        if (selectedItem.locationId && selectedItem.locationId.endsWith('-2')) {
          // 查找所有相邻库位（前缀相同，尾数分别为-1和-2）
          const mainPart = selectedItem.locationId.substring(0, selectedItem.locationId.lastIndexOf('-'));
          const relatedStocks = this.STOCKList.filter(item =>
            item.barcode === selectedItem.barcode &&
            item.locationId === `${mainPart}-1`
          );

          if (relatedStocks.length > 0) {
            // 检查是否所有相关库存的状态都是0
            const allStatusZero = relatedStocks.every(stock => stock.sts === "0");

            debugger
            if (allStatusZero) {
              // 提示用户，显示库位信息和物料名称
              const message = relatedStocks.map(stock =>
                `此库位: <span style="color: #51c151;">${stock.locationId}</span>物料型号为: <span style="color: #ec0f40;">${stock.barcode}</span> 可以优先出库`
              ).join('<br>'); // 使用 <br> 进行换行

              this.$confirm(message, '温馨提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'info',
                dangerouslyUseHTMLString: true, // 允许使用 HTML
                closeOnClickModal: false, // 禁用点击遮罩层关闭
                closeOnPressEscape: false // 禁用按下 Esc 键关闭
              }).then(() => {
                relatedStocks.forEach(c => {
                  this.createTask(c);
                });
              }).catch(() => {
                this.createTask(selectedItem)
              });
            } else {
              // 如果有任何一个库位的状态不是0，直接走否
              this.stock.forEach(c => {
                this.createTask(c);
              })
            }
          } else {
            // 走2库位
            this.stock.forEach(c => {
              this.createTask(c);
            })
          }
        } else {
          this.stock.forEach(c => {
            this.createTask(c);
          })
        }
      });
    },


    clickIce(con) {
      this.form.sts = con;
      this.$modal.confirm('修改数据的状态？').then(() => {
        // 使用箭头函数，确保 this 指向 Vue 实例
        updateSts({locationId: this.locationId, status: this.form.sts}).then(response => {
          this.getList();
          this.dialogVisible = false;
        });
      }).catch(() => {
        // 用户点击了“否”或关闭了对话框
        console.log('用户取消了操作');
      });
    },


    createTask(stock) {
      this.$modal.confirm('是否创建任务？').then(() => {
        creates({putinId: this.putinId})
          .then(() => {
            this.getList();
            this.getStockList();
            this.$modal.msgSuccess("任务创建成功");
          })
          .catch(() => {
            // 处理错误
          });
      }).catch(() => {
        // 用户点击了“否”或关闭了对话框
        console.log('用户取消了操作');
      });

    },
    tableRowClassName(row, index) {
      if (row.sts === '0') {
        return 'warning-row';
      } else if (row.sts === 1) {
        return 'success-row';
      }
      return '';
    },
    handleConfirm() {
      this.$modal.confirm('是否修改此库位的订单状态？').then(() => {
        updateCkSts({locationId: this.locationId, status: this.form.sts}).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.getList();
          this.dialogVisible = false; // 显示对话框
        })
      }).catch(() => {
      });
    },

  }
};
</script>
<style scoped>
/* 可以根据需要自定义标题样式 */
.card-header-title {
  font-weight: bold;
  color: #333;
}
</style>
